package com.zts.base.resource;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.ResourceSupport;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Zhangkh on 2017/5/31.
 */
public class BaseResource extends ResourceSupport {
    private HashMap<String, BaseResource> embedded = null;

    public void embed(String key, BaseResource value) {
        if (this.embedded == null) {
            this.embedded = new HashMap<>();
        }

        this.embedded.put(key, value);
    }

    public void remove(String key) {
        if (this.embedded != null) {
            this.embedded.remove(key);
        }
    }

    public void transform(Object obj) {

    }

    @JsonProperty("_embedded")
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    public Map<String, BaseResource> getEmbedded() {
        return this.embedded;
    }

    @Override
    @JsonIgnore
    @JsonProperty("_links")
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    public List<Link> getLinks() {
        return super.getLinks();
    }
}
